# Contributor: Abdó Roig-Maranges <abdo.roig@gmail.com>

_realname=git-lfs
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=3.3.0
pkgsrc=${_realname}-${pkgver}
pkgrel=2
arch=(any)
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
pkgdesc="An open source Git extension for versioning large files (mingw-w64)"
url="https://git-lfs.github.com/"
license=('spdx:MIT')
options=('!strip')
depends=("git")
makedepends=("unzip"
             "patch"
             "${MINGW_PACKAGE_PREFIX}-go"
             #"${MINGW_PACKAGE_PREFIX}-ruby"
             )
source=("${pkgsrc}.tar.gz::https://github.com/git-lfs/git-lfs/releases/download/v${pkgver}/${_realname}-v${pkgver}.tar.gz"
        "https://github.com/git-lfs/git-lfs/commit/de6a135d731b9e98ca9da043f346794ea6bc4ecb.patch")
# Extract sources ourselves (avoid bsdtar failure in pull #2406)
noextract=(${pkgsrc}.tar.gz)
sha256sums=('964c200bb7dcd6da44cbf0cfa88575f7e48d26925f8ec86d634d3f83306a0920'
            'e095c7cbbc5a7409988b569903738bbea9b30127f40afb711b45a6dd60cab44e')

prepare() {
  # Extract sources ourselves (avoid bsdtar failure in pull #2406)
  [[ -d ${srcdir}/${pkgsrc} ]] && rm -rf ${srcdir}/${pkgsrc}
  tar -xf ${srcdir}/${pkgsrc}.tar.gz -C ${srcdir}

  # apply patches
  cd "${srcdir}/${pkgsrc}"

  # https://github.com/msys2/MINGW-packages/issues/15005
  patch -R -p1 -i "${srcdir}/de6a135d731b9e98ca9da043f346794ea6bc4ecb.patch"

  # Clear go cache
  #rm -Rf "${srcdir}/src"

  # Setup local gopath
  #mkdir -p "${srcdir}/src/github.com/git-lfs"
  #cp -R "${srcdir}/${pkgsrc}/" "${srcdir}/src/github.com/git-lfs/git-lfs"

  # Fetch dependencies
  #. ${MINGW_PREFIX}/etc/profile.d/go.sh
  #GOPATH="${srcdir}" go get -v -d

  #gem install ronn
}

build() {
  cd "${srcdir}/${pkgsrc}"

  ${MINGW_PREFIX}/bin/go build \
    -gcflags "all=-trimpath=${PWD}" \
    -asmflags "all=-trimpath=${PWD}" \
    .

  # build
  #. ${MINGW_PREFIX}/etc/profile.d/go.sh
  #GOPATH="${srcdir}" go run script/*.go -cmd build
  #GOPATH="${srcdir}" make

  # The man pages need ronn, which needs a bunch of missing ruby dependencies.
  #ronn docs/man/*.ronn
}

package() {
  cd "${srcdir}/${pkgsrc}"
  install -Dm755 "git-lfs.exe" "${pkgdir}${MINGW_PREFIX}/bin/git-lfs"
  install -Dm644 LICENSE.md "${pkgdir}${MINGW_PREFIX}"/share/licenses/${_realname}/LICENSE
  # man page
  #install -d "${pkgdir}${MINGW_PREFIX}/share/man/man1"
  #install -Dm644 docs/man/*.1 "${pkgdir}${MINGW_PREFIX}/share/man/man1"
}

